var win = Titanium.UI.currentWindow;

var pageHeading = Ti.UI.createLabel({
	text: 'Zagovori diplomskih',
	color:'#3E3F87',
	font:{
		fontSize:20,
		fontWeight:'bold'
	},
	top:5,
	textAlign: 'center',
	height:'auto'
});

win.add(pageHeading);
      
var data = [];  

var loader = Ti.Network.createHTTPClient({
    onload: function(e) {
    	
    	var doc = this.responseXML.documentElement;
		var zagovori = doc.getElementsByTagName("Zagovor");
		var x = 0;
		var naslov = "Zagovori diplomskih nalog";
		
		
		for (var c = 0; c < zagovori.length; c++)
		{
			var zagovor = zagovori.item(c);
			
			var ime = zagovor.getElementsByTagName("ImeKandidata").item(0).text;
			var diplomska = zagovor.getElementsByTagName("NaslovDiplomskegaDela").item(0).text;
			var kraj = zagovor.getElementsByTagName("DatumInMestoZagovora").item(0).text;
			
			var row = Ti.UI.createTableViewRow({height:'auto'});
			var labelime = Ti.UI.createLabel({
				text:ime,
				font : {fontSize : 25, fontWeight : 'bold', fontFamily : 'Arial' },
				color:'#000000',
				textAlign:'center',
				bottom:10,				
			});
			var rowd = Ti.UI.createTableViewRow({height:60});
			var labeldiplomska = Ti.UI.createLabel({
				text : diplomska,
				font : {fontSize : 20, fontStyle : 'italic', fontFamily : 'Arial' },
				color : '#000000',
				textAlign:'center',			
			});
			var rowk = Ti.UI.createTableViewRow({height:60});
			var labelkraj = Ti.UI.createLabel({
				text:kraj,
				font : {fontSize : 20, fontStyle : "italic", fontFamily : 'Arial' },
				color:'#000000',
				textAlign:'center',
				top:10,				
			});
				
			row.add(labelime);
			rowd.add(labeldiplomska);
			rowk.add(labelkraj);
				
			data[x++] = row;
			data[x++] = rowd;
			data[x++] = rowk;
		}
    	
    	var tableview = Titanium.UI.createTableView({data:data, separatorColor:'transparent', top: 40, layout: 'vertical'});
		Titanium.UI.currentWindow.add(tableview);
    	
	},
    onerror: function(e) {
        // this function is called when an error occurs, including a timeout
        Ti.API.debug(e.error);
        alert('error');
    },
	onreadystatechange: function(e) {
		Ti.API.debug(loader.readyState);
	},
    timeout:5000  /* in milliseconds */
});

loader.open("GET","https://164.8.251.99:9473/services/cir2012/FeriZagovori/FeriZagovori");

loader.send();